package com.dingreading.cloud.soms.service.impl;

import com.dingreading.cloud.soms.entity.Books;
import com.dingreading.cloud.soms.entity.table.BooksTableDef;
import com.dingreading.cloud.soms.mapper.BooksMapper;
import com.dingreading.cloud.soms.service.BooksService;
import com.mybatisflex.core.query.QueryCondition;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class BooksServiceImpl extends BaseServiceImpl<BooksMapper, Books, BooksTableDef> implements BooksService {

    @Override
    protected BooksTableDef getTable() {
        return BooksTableDef.books;
    }


    @Override
    public List<Books> getByIsbnOrBookNumNotInId(String isbn, List<Long> bookIds) {
        QueryCondition condition = table.isbn.eq(isbn).or(table.bookNum.eq(isbn));
        if (CollectionUtils.isNotEmpty(bookIds))
            condition.and(table.id.notIn(bookIds));

        return getMapper().selectListByCondition(condition);
    }

}
